/*
 *
 *  * Licensed to the Apache Software Foundation (ASF) under one
 *  * or more contributor license agreements.  See the NOTICE file
 *  * distributed with this work for additional information
 *  * regarding copyright ownership.  The ASF licenses this file
 *  * to you under the Apache License, Version 2.0 (the
 *  * "License"); you may not use this file except in compliance
 *  * with the License.  You may obtain a copy of the License at
 *  *
 *  *    http://www.apache.org/licenses/LICENSE-2.0
 *  *
 *  * Unless required by applicable law or agreed to in writing,
 *  * software distributed under the License is distributed on an
 *  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 *  * KIND, either express or implied.  See the License for the
 *  * specific language governing permissions and limitations
 *  * under the License.
 *
 */


// configure_cassandra.groovy 
// 
// Emits Cassandra config file based on environment and Cassandra node 
// registry in SimpleDB
//


String hostName  = (String)System.getenv().get("PUBLIC_HOSTNAME")
// build seed list by listing all Cassandra nodes found in SimpleDB domain with our stackName

NodeRegistry registry = new NodeRegistry();

def selectResult = registry.searchNode('cassandra')
def seeds = ""
def sep = ""
for (host in selectResult) {
    seeds = "${seeds}${sep}${host}"
    sep = ","
}


//We need to point to at least 1 node in the cassandra cluster so that we can bootstrap monitoring
def usergridConfig = """

[cassandra]
seed_hosts = ${seeds}

#TODO, this doesn't seem to work, I think opscenter is broken.  Try this again at a later time and remove opscenter exclusion below
#[storage_cassandra]
#seed_hosts = ${hostName}
#api_port = 9160


"""

println usergridConfig
